import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/analysis/widget/tooltip_icon.dart';
import 'package:boss/ui/widget/charts/bar/bar_chart.dart';
import 'package:boss/ui/widget/label_button.dart';
import 'package:boss/ui/widget/shadow_radius_card.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class StaffCard<T extends num> extends StatelessWidget {
  final String title;
  final String titleTip;
  final List<BarData<T>> data;
  final VoidCallback onActionTap;
  final String unit;
  final BuildBarLabel labelBuilder;

  const StaffCard({
    Key key,
    this.title,
    this.titleTip,
    this.data,
    this.onActionTap,
    this.unit,
    this.labelBuilder,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DefaultTextStyle(
      style: TextStyleConstant().normal_1_28,
      child: ShadowRadiusCard(
        margin: EdgeInsets.only(
          bottom: 30.w,
        ),
        padding: EdgeInsets.all(
          20.w,
        ),
        child: Column(
          children: <Widget>[
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: <Widget>[
                Row(
                  children: <Widget>[
                    Text(
                      title,
                      style: TextStyle(
                        fontSize: 28.sp,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                    if (titleTip != null) ToolTipIcon(titleTip),
                    Container(
                      margin: EdgeInsets.only(
                        left: 14.w,
                      ),
                      child: Text(
                        '单位（$unit）',
                        style: TextStyleConstant().normal_3_22,
                      ),
                    ),
                  ],
                ),
                onActionTap == null
                    ? SizedBox()
                    : LabelButton(
                        title: '查看明细>',
                        textStyle: TextStyleConstant().blue_22,
                        onTap: onActionTap,
                      ),
              ],
            ),
            Container(
              margin: EdgeInsets.only(
                top: 25.w,
              ),
              child: BarChart<T>(
                width: double.infinity,
                height: 230,
                data: data,
                labelBuilder: (data) {
                  return unit == '元' ? '¥${data.value}' : '${data.value}';
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
